//
//  HomePageViewController.m
//  框架
//
//  Created by 这是工作本 on 15/12/25.
//  Copyright © 2015年 这是工作本. All rights reserved.
//

#import "HomePageViewController.h"

@interface HomePageViewController () < UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain) UICollectionView *HcollectionV;
@property (nonatomic, retain) UICollectionView *VcollectionV;
@property (nonatomic, retain) UIView *scrollView;
@property (nonatomic, retain) UIView *line_basic;
@property (nonatomic, retain) NSMutableArray *HomeArr;
@property (nonatomic, assign) NSInteger begin_scroll;
@property (nonatomic, retain) UIScrollView *scroV;
@property (nonatomic, retain) UIPageControl *pageC;
@property (nonatomic, retain) NSArray *detailArr;
@property (nonatomic, assign) NSInteger i;
@property (nonatomic, retain) NSTimer *myTimer;
@property (nonatomic, retain) MBProgressHUD * hud;
@property (nonatomic, retain) UIImageView *viewA;
@property (nonatomic, retain) UIButton *ball;
@property (nonatomic, retain) UIButton *club;
@property (nonatomic, retain) UIButton *topic;
@property (nonatomic, retain) UIButton *activity;
@property (nonatomic, retain) UITableView *tableV;
@property (nonatomic, retain) UIImageView *imageView ;

@end

@implementation HomePageViewController

- (NSMutableArray *)HomeArr
{
    if (nil == _HomeArr) {
        
        self.HomeArr = [NSMutableArray array];
    }
    return _HomeArr;
}


- (void)viewWillAppear:(BOOL)animated
{
    self.viewA.hidden = NO;
    self.tabBarController.tabBar.hidden = NO;
}

- (void)viewWillDisappear:(BOOL)animated
{
    self.viewA.hidden = YES;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
       self.HomeArr = [NSMutableArray array];
    self.navigationItem.title = @"首页";
    [self getNetData];
    
    self.view.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];

    self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:29 / 255.0 green:127 / 255.0  blue:140 / 255.0  alpha:1.0];
    //城市
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"北京" style:UIBarButtonItemStylePlain target:self action:@selector(left)];
    //关掉自偏移
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    //设置字体颜色大小
    [self.navigationItem.leftBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                   [UIFont fontWithName:@"Helvetica" size:16.0 * ScreenWidth], NSFontAttributeName, [UIColor colorWithRed:255 / 255.0 green:255 / 255.0  blue:255 / 255.0  alpha:1.0], NSForegroundColorAttributeName,nil] forState:UIControlStateNormal];
    
    
    // 显示正在网络请求
//    self.hud = [[MBProgressHUD alloc] initWithView:self.view];
//    [self.view addSubview:self.hud];
//    self.hud.labelText = @"Loading";
//    //改变了加载Loading的样式
//    
//    self.hud.labelFont = [UIFont fontWithName:@"American Typewriter" size:16 * ScreenWidth];
//    [self.hud show:YES];

    
    //设置barbutton颜色
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor colorWithRed:207 / 255.0 green:146 / 255.0 blue:19 / 255.0 alpha:1.0];
    //消息
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"椭圆-17@2x.png"] style:UIBarButtonItemStylePlain target:self action:@selector(right)];
    
    self.navigationItem.rightBarButtonItem.tintColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    
//    //横向collectionView
//    UICollectionViewFlowLayout *flowL_H = [[UICollectionViewFlowLayout alloc] init];
//    //最小行间距
//    flowL_H.minimumLineSpacing = 10 * ScreenWidth;
//    //滚动方向
//    flowL_H.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//    //单位大小
//    flowL_H.itemSize = CGSizeMake(([UIScreen mainScreen].bounds.size.width - 30) / 4, 40 * ScreenHeigth);
//    //与屏幕四边的间距
//    flowL_H.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
//    
//    self.HcollectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width, 40 * ScreenHeigth) collectionViewLayout:flowL_H];
//    //隐藏指示条
//    self.HcollectionV.showsHorizontalScrollIndicator = NO;
//    //关掉滑动
//    self.HcollectionV.scrollEnabled = NO;
//    //关闭自动偏移
//    self.automaticallyAdjustsScrollViewInsets = NO;
//    self.HcollectionV.backgroundColor = [UIColor colorWithRed:25 / 255.0  green:25 / 255.0 blue:25 / 255.0 alpha:1.0];
//    self.HcollectionV.contentOffset = CGPointMake([[UIScreen mainScreen] bounds].size.width  / 4,  0);
//    //签协议
//    self.HcollectionV.delegate = self;
//    self.HcollectionV.dataSource = self;
//    //注册cell
//    [self.HcollectionV registerClass:[ChoiceGoodsHorizontalCollectionViewCell class] forCellWithReuseIdentifier:@"horizontalCell"];
//    self.HcollectionV.bounces = NO;
//    self.HcollectionV.pagingEnabled = YES;
//    
//    [self.view addSubview:self.HcollectionV];
//    
//    //滑条
//    self.scrollView = [[UIView alloc] initWithFrame:CGRectMake(5 * ScreenWidth, self.HcollectionV.frame.origin.y + self.HcollectionV.frame.size.height + 1 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width / 4 - 3 * 10 * ScreenWidth, 1 * ScreenHeigth)];
//    self.scrollView.backgroundColor = [UIColor colorWithRed:230 / 255.0 green:230 / 255.0 blue:230 / 255.0 alpha:1.0];
//    [self.view addSubview:self.scrollView];
    
    //纵向collectionView
//    UICollectionViewFlowLayout *flowL_V = [[UICollectionViewFlowLayout alloc] init];
//    //最小行间距
//    flowL_V.minimumLineSpacing = 0;
//    //滚动方向
//    flowL_V.scrollDirection = UICollectionViewScrollDirectionHorizontal;
//    //单位大小
//    flowL_V.itemSize = CGSizeMake([UIScreen mainScreen].bounds.size.width, self.view.frame.size.height - 65 * ScreenHeigth - 39 * ScreenHeigth);
//    
    //设置轮播图
    

    self.scroV = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 64, [UIScreen mainScreen].bounds.size.width , 200 * ScreenHeigth)];
    self.scroV.pagingEnabled = YES;
    //签协议拽动
    self.scroV.delegate = self;
    self.scroV.backgroundColor = [UIColor colorWithRed:25 / 255.0 green:25 / 255.0 blue:25 / 255.0 alpha:1.0];
    
    [self.view addSubview:self.scroV];
    //加两个图片槽
    self.scroV.contentSize = CGSizeMake([UIScreen mainScreen].bounds.size.width * 3, 0);
    //关闭边缘反弹
    self.scroV.bounces = NO;
    
    //设置pageController
    self.pageC = [[UIPageControl alloc] initWithFrame:CGRectMake(self.scroV.frame.origin.x + 100 * ScreenWidth, self.scroV.frame.origin.y + 200 * ScreenHeigth - 40 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width - 200 * ScreenWidth, 20 * ScreenHeigth)];
    self.pageC.numberOfPages = 1;
    self.pageC.pageIndicatorTintColor = [UIColor colorWithRed:230 / 255.0 green:230 / 255.0 blue:230 / 255.0 alpha:1.0];
    self.pageC.currentPageIndicatorTintColor = [UIColor colorWithRed:200 / 255.0 green:200 / 255.0 blue:200 / 255.0 alpha:1.0];
    [self.view addSubview:self.pageC];
    
    
    
    //定时器
//    self.myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(playAction:) userInfo:nil repeats:YES];
    
    self.i = 0;
    
    //显示第几个图片槽
    self.scroV.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width , 1);
    
    //与屏幕四边的间距
//    self.VcollectionV = [[UICollectionView alloc] initWithFrame:CGRectMake(0, 244 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, self.view.frame.size.height - 60 * ScreenHeigth - 39 * ScreenHeigth) collectionViewLayout:flowL_V];
//    //隐藏指示条
//    self.VcollectionV.showsHorizontalScrollIndicator = NO;
//    //关闭自动偏移
//    self.automaticallyAdjustsScrollViewInsets = NO;
//    //点击状态栏返回顶部
//    self.VcollectionV.scrollsToTop = YES;
//    self.VcollectionV.bounces = NO;
//    self.VcollectionV.backgroundColor = [UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0];
//    ;
//    //签协议
//    self.VcollectionV.delegate = self;
//    self.VcollectionV.dataSource = self;
//    //注册cell
//    [self.VcollectionV registerClass:[ChoiceGoodsVerticalCollectionViewCell class] forCellWithReuseIdentifier:@"verticalCell"];
//    //整页滑动
//    
//    self.VcollectionV.pagingEnabled = YES;
//    
//    [self.view addSubview:self.VcollectionV];
    
    //分割线
    //    self.line_basic = [[UIView alloc] initWithFrame:CGRectMake(0, 42 * ScreenHeigth, self.view.frame.size.width, 0.5)];
    //    self.line_basic.backgroundColor = [UIColor clearColor];
    //    [self.view addSubview:self.line_basic];
    
    //约球
    
    self.ball = [UIButton buttonWithType:UIButtonTypeCustom];
    self.ball.frame = CGRectMake(30 * ScreenWidth, self.scroV.frame.origin.y + self.scroV.frame.size.height + 20 * ScreenHeigth, 60 * ScreenWidth, 60 * ScreenHeigth);
    [self.ball setImage:[UIImage imageNamed:@"椭圆-13-拷贝@2x.png"] forState:UIControlStateNormal];
    [self.ball addTarget:self action:@selector(ballAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.ball];
    
    UILabel *ball = [[UILabel alloc] initWithFrame:CGRectMake(self.ball.frame.origin.x + 17 * ScreenWidth, self.ball.frame.origin.y + self.ball.frame.size.height + 5 * ScreenHeigth, 24 * ScreenWidth, 24 * ScreenHeigth)];
    ball.textColor = [UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0];
    ball.font = [UIFont systemFontOfSize:12.0 * ScreenWidth];
    ball.text = @"约球";
    [self.view addSubview:ball];
    
    //俱乐部
    
    self.club = [UIButton buttonWithType:UIButtonTypeCustom];
    self.club.frame = CGRectMake(self.ball.frame.origin.x + self.ball.frame.size.width + 35 * ScreenWidth, self.ball.frame.origin.y, self.ball.frame.size.width, self.ball.frame.size.height);
    [self.club setImage:[UIImage imageNamed:@"形状-23-拷贝-2@2x.png"] forState:UIControlStateNormal];
    [self.club addTarget:self action:@selector(clubAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.club];

    UILabel *club = [[UILabel alloc] initWithFrame:CGRectMake(self.club.frame.origin.x + 17 * ScreenWidth, self.club.frame.origin.y + self.club.frame.size.height + 5 * ScreenHeigth, 40 * ScreenWidth, 24 * ScreenHeigth)];
    club.textColor = [UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0];
    club.font = [UIFont systemFontOfSize:12.0 * ScreenWidth];
    club.text = @"俱乐部";
    [self.view addSubview:club];

    
    //话题
    
    self.topic = [UIButton buttonWithType:UIButtonTypeCustom];
    self.topic.frame = CGRectMake(self.club.frame.origin.x + self.club.frame.size.width + 35 * ScreenWidth, self.ball.frame.origin.y, self.ball.frame.size.width, self.ball.frame.size.height);
    [self.topic setImage:[UIImage imageNamed:@"形状-25-拷贝-2@2x.png"] forState:UIControlStateNormal];
    [self.topic addTarget:self action:@selector(topicAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.topic];

    UILabel *topic = [[UILabel alloc] initWithFrame:CGRectMake(self.topic.frame.origin.x + 17 * ScreenWidth, self.topic.frame.origin.y + self.topic.frame.size.height + 5 * ScreenHeigth, 24 * ScreenWidth, 24 * ScreenHeigth)];
    topic.textColor = [UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0];
    topic.font = [UIFont systemFontOfSize:12.0 * ScreenWidth];
    topic.text = @"话题";
    [self.view addSubview:topic];

    
    //活动
    
    self.activity = [UIButton buttonWithType:UIButtonTypeCustom];
    self.activity.frame = CGRectMake(self.topic.frame.origin.x + self.topic.frame.size.width + 35 * ScreenWidth, self.ball.frame.origin.y, self.ball.frame.size.width, self.ball.frame.size.height);
    [self.activity setImage:[UIImage imageNamed:@"形状-30@2x.png"] forState:UIControlStateNormal];
    [self.activity addTarget:self action:@selector(activityAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:self.activity];

    UILabel *activity = [[UILabel alloc] initWithFrame:CGRectMake(self.activity.frame.origin.x + 17 * ScreenWidth, self.activity.frame.origin.y + self.activity.frame.size.height + 5 * ScreenHeigth, 24 * ScreenWidth, 24 * ScreenHeigth)];
    activity.textColor = [UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0];
    activity.font = [UIFont systemFontOfSize:12.0 * ScreenWidth];
    activity.text = @"活动";
    [self.view addSubview:activity];
    
    //分割线
    UIView *viewD = [[UIView alloc] initWithFrame:CGRectMake(0, ball.frame.origin.y + ball.frame.size.height + 5 * ScreenWidth, [UIScreen mainScreen].bounds.size.width, 0.2 * ScreenHeigth)];
    viewD.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:viewD];
    
    //资讯
    
    self.tableV = [[UITableView alloc] initWithFrame:CGRectMake(0, ball.frame.origin.y + ball.frame.size.height + 10 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height - ball.frame.origin.y - ball.frame.size.height - 49 * ScreenHeigth) style:UITableViewStylePlain];
    self.tableV.dataSource = self;
    self.tableV.delegate = self;
    //    self.tableV.backgroundColor = [UIColor colorWithRed:30 / 255.0 green:30 / 255.0 blue:30 / 255.0 alpha:1.0];
    [self.view addSubview:self.tableV];
    
    //解决左边空白问题
    if ([self.tableV respondsToSelector:@selector(setSeparatorInset:)]) {
        
        [self.tableV setSeparatorInset:UIEdgeInsetsZero];
    }
    
    if ([self.tableV respondsToSelector:@selector(setLayoutMargins:)])
    {
        [self.tableV setLayoutMargins:UIEdgeInsetsZero];
    }
    
    
    
    
}

- (void)getNetData
{
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];

    [manager GET:@"http://192.168.1.157:8080/api/center?userId=3339WrRIAYfv9wPeGqC&equipment=ios&requestType=Home_Api&token=74214cd04c081efd29a1f55d3d7b6c3a" parameters:nil success:^(AFHTTPRequestOperation * _Nonnull operation, id  _Nonnull responseObject) {
        
        NSArray *dataArr = [responseObject objectForKey:@"data"];
        
        
        for (NSDictionary * dic in dataArr) {
            
        NSArray *value = [dic objectForKey:@"value"];
            
            for (NSDictionary *dict in value) {
                
                Homepage *home = [[Homepage alloc] init];

                [home setValuesForKeysWithDictionary:dict];
                
                [self.HomeArr addObject:home];
 
                
            }
            
        
        }
        
        
        [self.tableV reloadData];
        
        
        
        
    } failure:^(AFHTTPRequestOperation * _Nullable operation, NSError * _Nonnull error) {
        
        NSLog(@"%@", error);
        
    }];
    
    
}


//代理方法解决15像素空白问题

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([cell respondsToSelector:@selector(setSeparatorInset:)])
    {
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setLayoutMargins:)])
    {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

//约球
- (void)ballAction:(UIButton *)sender
{
    
}
//俱乐部
- (void)clubAction:(UIButton *)sender
{
    
}

//资讯
- (void)topicAction:(UIButton *)sender
{
    
}

//活动
- (void)activityAction:(UIButton *)sender
{
    
}



- (void)playAction:(NSTimer *)sender
{
    
    // 显示第二张图,我们需要的第一张图
    // 图片坐标加1 (加动画轮播图)
    [UIView animateWithDuration:1 animations:^{
        
        self.scroV.contentOffset = CGPointMake(self.view.frame.size.width * (self.i + 1), 0);
    }];

    
    self.pageC.currentPage = self.i;
    self.i += 1;

    
    
    if (self.i == self.detailArr.count) {
        self.i = 0;
    }
    
}


//手动滑动时关闭计时器
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    [_myTimer invalidate];
    self.myTimer = nil;
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 180 * ScreenHeigth;
}


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSString *cellStr = @"cell";
    HomepageTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellStr];

    if (nil == cell) {
        
        cell = [[HomepageTableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:cellStr];
    }
    cell.backgroundColor = [UIColor colorWithRed:255 / 255.0 green:255 / 255.0 blue:255 / 255.0 alpha:1.0];
    
    //清除选中色
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    if (0 == self.HomeArr.count) {
        
        
    } else
    {
        Homepage *home = [self.HomeArr objectAtIndex:indexPath.row];
        
        [cell cellFordata:home];
        
        //加两个图片
        for (NSInteger i = 0  ; i < 3 + 2; i++) {
            
            self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake([UIScreen mainScreen].bounds.size.width * i, 0, self.view.frame.size.width, 200 * ScreenHeigth)];
            [self.imageView sd_setImageWithURL:@"http://192.168.1.157:8080/api/mechanism/file/imageMobile/10/com.bra.modules.cms.entity.Article/pic?width=750&height=200&random=79" placeholderImage:nil];
            
            //加一个首尾图片
            if (0 == i) {
//                [self.imageView sd_setImageWithURL:[home.imageSrc objectAtIndex:home.imageSrc.count - 1] placeholderImage:nil];
                
                [self.scroV addSubview:self.imageView];
            }else if (3 + 1 == i)
            {
                
//                    [self.imageView sd_setImageWithURL:[home.imageSrc objectAtIndex:0] placeholderImage:nil];
                
                [self.scroV addSubview:self.imageView];
                
            }else {
                
//                            [self.imageView sd_setImageWithURL:[home.imageSrc objectAtIndex:i - 1] placeholderImage:nil];
                
                [self.scroV addSubview:self.imageView];
            }
            
            
        }


        
    }
    
  
    
    return cell;
    
}




//点击触发
//- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    if (self.HcollectionV == collectionView) {
//        //动画滑块 点击改变滑块位置
//        [UIView animateWithDuration:0.2 animations:^{
//            
//            self.scrollView.frame = CGRectMake(5 * ScreenWidth + ([UIScreen mainScreen].bounds.size.width / 4) * indexPath.row, self.HcollectionV.frame.origin.y + self.HcollectionV.frame.size.height + 1 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width / 4 - 3 * 10 * ScreenWidth, 1 * ScreenHeigth);
//            
//        }];
//        //改变collection的偏移量
//        [self.VcollectionV setContentOffset:CGPointMake(self.view.frame.size.width * indexPath.row, 0) animated:YES];
//        //滑块一起移动->体验非常好
//        self.begin_scroll = indexPath.row;
//        [collectionView scrollToItemAtIndexPath:indexPath atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:YES];
//        
//    }
//    
//}



//*
//滑动开始存储一个数值在减速结束的时候判断
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    
    if (scrollView == self.VcollectionV) {
        self.begin_scroll = scrollView.contentOffset.x / self.view.frame.size.width;
        if (scrollView.contentOffset.x < - 20) {
            
        }
    }
    
}
//减速结束
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView == self.VcollectionV) {
        
        NSInteger end_scroll = scrollView.contentOffset.x / self.view.frame.size.width;
        
        if ( end_scroll == self.begin_scroll && end_scroll == 0) {
            //改变滑块位置
            [UIView animateWithDuration:0.2 animations:^{
                self.scrollView.frame = CGRectMake(5 * ScreenWidth + ([UIScreen mainScreen].bounds.size.width / 4) * end_scroll, self.HcollectionV.frame.origin.y + self.HcollectionV.frame.size.height + 1 * ScreenHeigth, [UIScreen mainScreen].bounds.size.width / 4 - 3 * 10 * ScreenWidth, 1 * ScreenHeigth);
                
            }];
            [self moveBack:end_scroll];
        }
        if (end_scroll != self.begin_scroll) {
            //改变滑块位置(坐标)
            [UIView animateWithDuration:0.2 animations:^{
                self.scrollView.frame = CGRectMake(5 * ScreenWidth + ([UIScreen mainScreen].bounds.size.width / 4) * end_scroll, self.HcollectionV.frame.origin.y + self.HcollectionV.frame.size.height + 1 * ScreenHeigth,[UIScreen mainScreen].bounds.size.width / 4 - 3 * 10 * ScreenWidth, 1 * ScreenHeigth);
                
            }];
            
            //往前滑还是往后滑
            if (end_scroll > self.begin_scroll) {
                
                [UIView animateWithDuration:0.2 animations:^{
                    
                    [self moveGoView:end_scroll];
                    
                }];
                
            }
            //额外判断直接拉到最前面==0界面滑块不动的问题
            if (end_scroll == 0) {
                
                [UIView animateWithDuration:0.2 animations:^{
                    
                    [self moveBack:end_scroll];
                    
                }];
            }
            else
            {
                [UIView animateWithDuration:0.2 animations:^{
                    
                    [self moveBack:end_scroll];
                    
                }];
            }
            
        }
    }
    
    
    
    //计时器停止后pageC和scroV关联
    self.pageC.currentPage = self.scroV.contentOffset.x / [UIScreen mainScreen].bounds.size.width - 1;
    if (self.detailArr.count + 1  == self.scroV.contentOffset.x / [UIScreen mainScreen].bounds.size.width) {
        self.pageC.currentPage = 0;
        self.scroV.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width , 0);
    }else if (0 == self.scroV.contentOffset.x / [UIScreen mainScreen].bounds.size.width)
    {
        self.pageC.currentPage = self.detailArr.count - 1;
        self.scroV.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width * self.detailArr.count + 1, 0);
        
    }
    
    //定时器
    self.myTimer = [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(playAction:) userInfo:nil repeats:YES];
    
    self.i = self.pageC.currentPage;
    
    
    
    
    
}
//滑块判断->向前滑
- (void)moveGoView:(NSInteger)view
{
    
    if (view > 1 && view < 3) {
        self.HcollectionV.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width / 4 * (view - 2), 0);
        
    }
    if (view > 2) {
        self.HcollectionV.contentOffset = CGPointMake([UIScreen mainScreen].bounds.size.width / 4 , 0);
    }
    
}
//滑块判断->向后滑
- (void)moveBack:(NSInteger)view
{
    
    if (view >= 2 && view < 3) {
        self.HcollectionV.contentOffset = CGPointMake(([UIScreen mainScreen].bounds.size.width - 30 * ScreenWidth) / 4 * (view - 2), 0);
        
    }
    
    
    if (view < 2) {
        
        self.HcollectionV.contentOffset = CGPointMake(0, 0);
    }
}



//- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
//{
//    if (self.HcollectionV == collectionView) {
//        
//        return 4;
//        
//    } else {
//        
//        return 4;
//    }
//}
//
//
//- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
//{
//    if (self.HcollectionV == collectionView) {
//        
//        ChoiceGoodsHorizontalCollectionViewCell *hor = [collectionView dequeueReusableCellWithReuseIdentifier:@"horizontalCell" forIndexPath:indexPath];
//        
//        
//        hor.backgroundColor = [UIColor colorWithRed:25 / 255.0 green:25 / 255.0 blue:25 / 255.0 alpha:1.0];
//        return hor;
//        
//    } else {
//        
//        
//        ChoiceGoodsVerticalCollectionViewCell *ver = [collectionView dequeueReusableCellWithReuseIdentifier:@"verticalCell" forIndexPath:indexPath];
//        //        [ver data:self.detailArr];
//        ver.imageArr = self.detailArr;
//        
//        
//        return ver;
//    }
//}

//提示框
- (void)left
{
    
    UIAlertView *alertv = [[UIAlertView alloc] initWithTitle:nil message:@"暂未开放其他城市" delegate:self cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [NSTimer scheduledTimerWithTimeInterval:1.0f target:self selector:@selector(timerAction:) userInfo:alertv repeats:YES];
    [alertv show];

    
    
}

- (void)timerAction:(NSTimer *)send
{
    UIAlertView *aler = (UIAlertView *)[send userInfo];
    [aler dismissWithClickedButtonIndex:0 animated:NO];
    aler = NULL;
}


- (void)right
{
    
    
        
    InformationViewController *information = [[InformationViewController alloc] init];
    [self.navigationController pushViewController:information animated:YES];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
